-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local lu = require 'luaunit'
local iic_process = require 'unit_manager.class.logic_fw.upgrade.iic_process'
local mc_utils = require 'mc.utils'
local file_sec = require 'utils.file'
local skynet = require 'skynet'

TestIICProcess = {}

function mock_plug() 
    return 0 
end

local fw_anlu_1 = {
    smc_chip = {["bmc.kepler.Chip.BlockIO"] = {
            Read = function()
                return '\x03\x00\x01\x01' -- i2c模式+anlu
            end
        }
    },
    i2c_upgrade_chip = {
        PluginRequest=mock_plug,
        Write = function() end
    },
    position = "123456"
}

function TestIICProcess:setupClass()
    ori_open_s = file_sec.open_s
    ori_close = mc_utils.close

    file_sec.open_s = function ()
        return {read=function () return 0 end}
    end
    mc_utils.close = function ()
        return 'test'
    end
end

function TestIICProcess:teardownClass()
    --recover function
    file_sec.open_s = ori_open_s
    mc_utils.close = ori_close
end

function TestIICProcess:test_iic_upgrade_cpld_anlu()
    local ret = iic_process.i2c_load_cpld(fw_anlu_1, '/tmp', _, _, _)
    lu.assertEquals(ret, 0)
end

return TestIICProcess